package cn.jcet.mapreduce.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/2 0:05
 *  输入 输出
 */
public class WordCountReduce extends Reducer<Text,IntWritable,Text,IntWritable> {

    private IntWritable v = new IntWritable(1);
    private int sum;
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
//        super.reduce(key, values, context);
        // 累加求和
        sum = 0;
        for (IntWritable count : values) {
            // 获取拆分的结果
            sum += count.get();
        }
        // 输出
        v.set(sum);
        context.write(key,v);



    }
}